//
//  CZNavigationController.m
//  nsj_iOS
//
//  Created by apple on 2016/12/27.
//  Copyright © 2016年 GCZ. All rights reserved.
//

#import "CZNavigationController.h"
#import "CZMyTaskDetailViewController.h"
@interface CZNavigationController ()<UIGestureRecognizerDelegate, UINavigationBarDelegate>

@end

@implementation CZNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.translucent = YES;
    self.navigationBar.tintColor = [UIColor whiteColor];
    NSDictionary * dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    self.navigationBar.titleTextAttributes = dict;
    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:mRGBColor(84, 138, 129)] forBarMetrics:(UIBarMetricsDefault)];
    [(UIView*)[self.navigationBar.subviews objectAtIndex:0] setAlpha:0.7f];

    self.interactivePopGestureRecognizer.delegate = self;
//    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    // 
    // Do any additional setup after loading the view.
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{

//    [(UIView*)[self.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];

    if (self.childViewControllers.count > 0) {
        // 如果viewController不是最早push进来的子控制器
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fh"] style:(UIBarButtonItemStylePlain) target:self action:@selector(back)];
        self.navigationBar.alpha = 1;
    
//        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:(UIBarButtonItemStylePlain) target:self action:@selector(back)];
        // 隐藏底部的工具条
//        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    // 所有设置搞定后, 再push控制器
    [super pushViewController:viewController animated:animated];
}
- (void)back {
    [self popViewControllerAnimated:YES];
}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 手势何时有效 : 当导航控制器的子控制器个数 > 1就有效
    return self.childViewControllers.count > 1;
}
- (void)dealloc {
    self.delegate = nil;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
